package com.spzx.user.api.factory;

import com.spzx.common.core.domain.R;
import com.spzx.user.api.RemoteUserService;
import com.spzx.user.domain.UserAddress;
import com.spzx.user.domain.UserInfo;
import com.spzx.user.domain.UserRegisterDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;

public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {

    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);
    @Override
    public RemoteUserService create(Throwable cause) {
        log.error("会员服务调用失败:{}", cause.getMessage());
        return new RemoteUserService()
        {

            @Override
            public R saveUserInfo(UserRegisterDTO userRegisterDTO) {
                return R.fail("会员注册保存数据失败");
            }

            @Override
            public R<UserInfo> getUserInfo(String username) {
                return R.fail("用户登录失败");
            }

            @Override
            public R<UserAddress> getUserAddressById(Long id) {
                return R.fail("远程调用根据id查询用户失败");
            }
        };
    }
}
